﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DTO;
using DAO;
using BUS;
namespace QLBANSACH
{
    public partial class TK : Form
    {
        SqlConnection connection = sqlConnectionData.Hamketnoi();
        //SqlConnection connection = new SqlConnection("Data Source=TUAN-PC\\SQLEXPRESS;Initial Catalog=QLBANMAYTINH;Integrated Security=True");

        public TK()
        {
            InitializeComponent();
        }

        private void TK_Load(object sender, EventArgs e)
        {
            connection.Open();
        }

        private void checkBox2_CheckedChanged_1(object sender, EventArgs e)
        {
            if (checkBox2.Checked == true)
            {
                checkBox1.Checked = false;
                checkBox3.Checked = false;
                numericUpDown1.Enabled = false;
                numericUpDown2.Enabled = false;
                textBox2.Enabled = false;
            }
            else
            {
                if (checkBox3.Checked == true)
                {
                    checkBox1.Checked = false;
                    //checkBox1.Checked = true;
                    numericUpDown1.Enabled = false;
                    numericUpDown2.Enabled = false;
                    textBox2.Enabled = false;
                }
            }
        }

        private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                checkBox2.Checked = false;
                checkBox3.Checked = false;
                numericUpDown1.Enabled = true;
                numericUpDown2.Enabled = true;
                textBox2.Enabled = true;
            }
            else
            {
                if (checkBox2.Checked == true)
                {
                    checkBox3.Checked = false;
                    //checkBox2.Checked = true;
                    numericUpDown1.Enabled = false;
                    numericUpDown2.Enabled = false;
                    textBox2.Enabled = false;
                }
            }
        }

        private void checkBox3_CheckedChanged_1(object sender, EventArgs e)
        {
            if (checkBox3.Checked == true)
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                numericUpDown1.Enabled = false;
                numericUpDown2.Enabled = false;
                textBox2.Enabled = false;
            }
            else
            {
                if (checkBox1.Checked == true)
                {
                    checkBox2.Checked = false;
                    numericUpDown1.Enabled = true;
                    numericUpDown2.Enabled = true;
                    textBox2.Enabled = true;
                }
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked == true)
            {
                //NV_DTO nv = new NV_DTO(textBox1.Text, textBox1.Text);
                //dataGridView1.DataSource = NV_BUS.SeachNV(nv);
                DataTable tb = new DataTable();
                SqlCommand cm = new SqlCommand();
                cm.Connection = connection;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "SEACHNV";
                cm.Parameters.Add("@A", SqlDbType.NVarChar, 10).Value = textBox1.Text;
                cm.Parameters.Add("@B", SqlDbType.NVarChar, 50).Value = textBox1.Text;
                SqlDataReader dr = cm.ExecuteReader();
                tb.Load(dr);
                dataGridView1.DataSource = tb;
            }
            if (checkBox1.Checked == true)
            {
                DataTable tb = new DataTable();
                SqlCommand cm = new SqlCommand();
                cm.Connection = connection;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "SEACHSACH";
                cm.Parameters.Add("@A", SqlDbType.NVarChar, 10).Value = textBox1.Text;
                cm.Parameters.Add("@B", SqlDbType.NVarChar, 50).Value = textBox1.Text;
                SqlDataReader dr = cm.ExecuteReader();
                tb.Load(dr);
                dataGridView1.DataSource = tb;
            }
            if (checkBox3.Checked == true)
            {
                DataTable tb = new DataTable();
                SqlCommand cm = new SqlCommand();
                cm.Connection = connection;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "SEACHKH";
                cm.Parameters.Add("@A", SqlDbType.NVarChar, 10).Value = textBox1.Text;
                cm.Parameters.Add("@B", SqlDbType.NVarChar, 50).Value = textBox1.Text;
                SqlDataReader dr = cm.ExecuteReader();
                tb.Load(dr);
                dataGridView1.DataSource = tb;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                DataTable tb = new DataTable();
                SqlCommand cm = new SqlCommand();
                cm.Connection = connection;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "SEACHSACHTHEOGIA";
                cm.Parameters.Add("@A", SqlDbType.Int, 50).Value = Convert.ToInt32(numericUpDown1.Value);
                cm.Parameters.Add("@B", SqlDbType.Int, 50).Value = Convert.ToInt32(numericUpDown2.Value);
                SqlDataReader dr = cm.ExecuteReader();
                tb.Load(dr);
                dataGridView1.DataSource = tb;
            }
            else
            {
                DataTable tb = new DataTable();
                SqlCommand cm = new SqlCommand();
                cm.Connection = connection;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "SEACHTHEOTLSANDGIA1";
                cm.Parameters.Add("@A", SqlDbType.NVarChar, 10).Value = textBox2.Text;
                cm.Parameters.Add("@B", SqlDbType.Int, 50).Value = Convert.ToInt32(numericUpDown1.Value);
                cm.Parameters.Add("@C", SqlDbType.Int, 50).Value = Convert.ToInt32(numericUpDown2.Value);
                SqlDataReader dr = cm.ExecuteReader();
                tb.Load(dr);
                dataGridView1.DataSource = tb;
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            DataTable tb = new DataTable();
            SqlCommand cm = new SqlCommand();
            cm.Connection = connection;
            cm.CommandType = CommandType.StoredProcedure;
            cm.CommandText = "SEACHTHEOTLS";
            cm.Parameters.Add("@A", SqlDbType.NVarChar, 10).Value = textBox2.Text;
            SqlDataReader dr = cm.ExecuteReader();
            tb.Load(dr);
            dataGridView1.DataSource = tb;
        }
    }
}
